from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()


def create_app(config):
    app = Flask(__name__)
    with app.app_context():
        app.config.from_object(config)
        db.init_app(app)
        from .routes import api_blueprint, main_blueprint
        app.register_blueprint(main_blueprint)
        app.register_blueprint(api_blueprint, url_prefix="/api")
        from .routes.upload import init_upload
        init_upload(app)
    return app